package com.itheima.handle;

import com.itheima.ex.CustomerException;
import com.itheima.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 自定义异常
 * @author GY
 * @version V1.0
 * @date 2025-01-15 10:08
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public Result handlerException(Exception e){
        e.printStackTrace();
        log.error("全局异常处理器,捕获到的异常信息:{}",e);
        return Result.error("服务器正忙,请稍后重试");
    }

    @ExceptionHandler(CustomerException.class)
    public Result handleCustomerException(CustomerException e){
        e.printStackTrace();
        log.error("全局异常处理器,捕获到的自定义异常信息:{}",e);
        return Result.error(e.getMessage());
    }
}
